package com.chis.netty.http.client;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpContentDecompressor;
import io.netty.handler.codec.http.HttpObjectAggregator;

public class HttpClientInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    public void initChannel(SocketChannel ch) {
        ChannelPipeline p = ch.pipeline();
        p.addLast(new HttpClientCodec());

        // Remove the following line if you don't want automatic content
        // decompression.
        p.addLast(new HttpContentDecompressor());//这里要添加解压，不然打印时会乱码

        // Uncomment the following line if you don't want to handle
        // HttpContents.
        // p.addLast(new HttpObjectAggregator(1048576));
        p.addLast(new HttpObjectAggregator(123433));//添加HttpObjectAggregator， HttpClientMsgHandler才会收到FullHttpResponse
        p.addLast(new HttpClientMsgHandler());
    }

}
